package Util;

import com.sun.org.apache.xpath.internal.operations.Bool;

import java.sql.Timestamp;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * @since 2024-06-03
 * @author yooo_fan
 */
public class TimeUtil {
    /**
     * @return 当前时间戳
     */
    public static Timestamp getCurrentTimestamp() {
        return new Timestamp(System.currentTimeMillis());
    }

    /**
     * 判断一个Timestamp和一个LocalDate是否相同
     * @param timestamp timestamp
     * @param localDate localDate
     * @return 比较结果
     */
    public static Boolean getIfSame(Timestamp timestamp, LocalDate localDate){
        if(timestamp == null || localDate == null){
            return false;
        }
        LocalDate localDataFromTimestamp = timestamp.toLocalDateTime().toLocalDate();

        return localDate.equals(localDataFromTimestamp);
    }

    /**
     * 以字符串形式获取当前时间
     * @return 当前yyyy-MM-dd HH:mm:ss
     */
    public static String getCurrentDateTime() {
       return LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
    }
}
